package com.ruoyi.web.controller.Information;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.Information.domain.CommunityDocument;
import com.ruoyi.Information.service.ICommunityDocumentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社区资料Controller
 * 
 * @author xianyu
 * @date 2025-04-04
 */
@RestController
@RequestMapping("/Information/document")
public class CommunityDocumentController extends BaseController
{
    @Autowired
    private ICommunityDocumentService communityDocumentService;

    /**
     * 查询社区资料列表
     */
    @PreAuthorize("@ss.hasPermi('Information:document:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommunityDocument communityDocument)
    {
        startPage();
        List<CommunityDocument> list = communityDocumentService.selectCommunityDocumentList(communityDocument);
        return getDataTable(list);
    }

    /**
     * 导出社区资料列表
     */
    @PreAuthorize("@ss.hasPermi('Information:document:export')")
    @Log(title = "社区资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommunityDocument communityDocument)
    {
        List<CommunityDocument> list = communityDocumentService.selectCommunityDocumentList(communityDocument);
        ExcelUtil<CommunityDocument> util = new ExcelUtil<CommunityDocument>(CommunityDocument.class);
        util.exportExcel(response, list, "社区资料数据");
    }

    /**
     * 获取社区资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('Information:document:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(communityDocumentService.selectCommunityDocumentById(id));
    }

    /**
     * 新增社区资料
     */
    @PreAuthorize("@ss.hasPermi('Information:document:add')")
    @Log(title = "社区资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommunityDocument communityDocument)
    {
        return toAjax(communityDocumentService.insertCommunityDocument(communityDocument));
    }

    /**
     * 修改社区资料
     */
    @PreAuthorize("@ss.hasPermi('Information:document:edit')")
    @Log(title = "社区资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommunityDocument communityDocument)
    {
        return toAjax(communityDocumentService.updateCommunityDocument(communityDocument));
    }

    /**
     * 删除社区资料
     */
    @PreAuthorize("@ss.hasPermi('Information:document:remove')")
    @Log(title = "社区资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(communityDocumentService.deleteCommunityDocumentByIds(ids));
    }
}
